#ifndef _mandelbrot_h_
#define _mandelbrot_h_

/**
  * @brief Data structure used to store
  * a complex number and iterate over the
  * mandelbrot function.
  */
struct Complex {
  double real;
  double im;

  Complex (double preal, double pim)
    : real(preal), im(pim) {
  }

  void square_add (Complex& other) {
    double temp = real;
    real = real*real - im*im + other.real;
    im = 2.f*temp*im + other.im;
  }

  double module_square () {
    return real*real + im*im;
  }
};

/**
  * Core function determining if a point of the plane
  * belongs to the mandelbrot set or not.
  *
  * \param x,y Input point
  * \param niter Number of iterations used to limitate the
  * depth of the recursion when testing if a term of the mandelbrot
  * suite belongs to the D(0,2) disc or not.
  * \return The number of iterations reached by the algorithm.
  */
bool in_mandelbrot_set (const double x, const double y,
                        int& nsteps, const int niter = 16);

#endif

